<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of bpServer
 *
 * @author QuangKhoi
 */
class bpServer {
    
    /*
     * @param soap_server
     */
    public $server;
    
    public function __construct($url) {
        $this->server = new soap_server();
        $this->server->configureWSDL($url);
        $this->complexType();
        $this->registerProc("testWS", array("data" => "tns:int"), array("return" => "tns:user"));
        $this->registerProc("Login", array("email" => "xsd:string", "password" => "xsd:string"), array("return" => "tns:userinfo"));
        $this->registerProc("getColorBar", array("url" => "xsd:string"), array("return" => "xsd:string"));
        $this->registerProc("addLike", array("statusid" => "xsd:int", "userid" => "xsd:int", "datecreated" => "xsd:string"), array("return" => "xsd:int"));
        $this->registerProc("getAmountLike", array("statusid" => "xsd:int"), array("return" => "xsd:int"));
        $this->registerProc("deleteLike", array("statusid" => "xsd:int", "userid" => "xsd:int"), array("return" => "xsd:string"));
        $this->registerProc("addFollow", array("userid1" => "xsd:int", "userid2" => "xsd:int", "datecreated" => "xsd:string"), array("return" => "xsd:int"));
        $this->registerProc("deleteFollow", array("userid1" => "xsd:int", "userid2" => "xsd:int"), array("return" => "xsd:string"));
        $this->registerProc("checkFollow", array("userid1" => "xsd:int", "userid2" => "xsd:int"), array("return" => "xsd:string"));
        $this->registerProc("deletePhotoData", array("photoid" => "xsd:int"), array("return" => "xsd:string"));
        $this->registerProc("deleteStatus", array("statusid" => "xsd:int"), array("return" => "xsd:string"));
    }
    
    public function complexType() {    
        //ComplexType for User
        $this->server->wsdl->addComplexType('user', 'complexType', 'struct', 'user', '',
                array(
                    'userId' => array('name' => 'userId', 'type' => 'xsd:int'),
                    'email' => array('name' => 'email', 'type' => 'xsd:string'),
                    'password' => array('name' => 'password', 'type' => 'xsd:string'),
                    'name' => array('name' => 'name', 'type' => 'xsd:string'),
                    'company' => array('name' => 'company', 'type' => 'xsd:string'),
                    'address' => array('name' => 'address', 'type' => 'xsd:string'),
                    'phone' => array('name' => 'phone', 'type' => 'xsd:string'),
                    'position' => array('name' => 'position', 'type' => 'xsd:string'),
                    'dateRegistered' => array('name' => 'dateRegistered', 'type' => 'xsd:date'),
                    'token' => array('name' => 'token', 'type' => 'xsd:string'),
                    'status' => array('name' => 'status', 'type' => 'xsd:int')));
        //ComplexType for UserInfo
        $this->server->wsdl->addComplexType('userinfo', 'complexType', 'struct', 'userinfo', '', array(
            'avatarid' => array('name' => 'avatarid', 'type' => 'xsd:int'),
            'username' => array('name' => 'username', 'type' => 'xsd:string'),
            'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
            'lastname' => array('name' => 'lastname', 'type' => 'xsd:string'),
            'address' => array('name' => 'address', 'type' => 'xsd:string'),
            'birthday' => array('name' => 'birthday', 'type' => 'xsd:date'),
            'email' => array('name' => 'email', 'type' => 'xsd:string'),
            'password' => array('name' => 'password', 'type' => 'xsd:string'),
            'role' => array('name' => 'role', 'type' => 'xsd:int'),
            'overallscore' => array('name' => 'overallscore', 'type' => 'xsd:int')));      
    }
    
    public function registerProc($procedure, $params, $returns, $style="rpc", 
            $use = "encoded", $description = "", $namespace = false, 
            $action = false) {
        $this->server->register($procedure,
                // parameter list:
                $params,
                // return value(s):
                $returns,
                // namespace:
                $namespace,
                // soapaction: (use default)
                $action,
                // style: rpc or document
                $style,
                // use: encoded or literal
                $use,
                // description: documentation for the method
                $description);
    }
    
    public function getStream($streamID, $start, $length) {
        $stream = Stream::withId(base64_decode($streamId));
    }
    
    /*
     * SOAP Procedures
     */
    public static function testWS($data) {
        return array('userId' => $data,
                        'email' => 'quangkhoidoan@gmail.com',
                        'password' => 'testpassword',
                        'name' => 'Khoi Doan',
                        'company' => '20-12-2013',
                        'address' => '',
                        'phone' => '0907244781',
                        'position' => '',
                        'dateRegistered' => '30-09-2013',
                        'token' => 'something in md5',
                        'status' => 'img');
    }
    
    public static function Login($email, $password){
        return User::Login($email, $password);
    }
    
    public static function deleteStatus($statusid){
        return Status::deleteStatus($statusid);
    }
    
    public static function deletePhotoData($photoid){
        return Photo::deletePhotoData($photoid);
    }
    
    public static function getColorBar($url){
        return Color::getColorBar($url);
    }
    
    public static function addFollow($userid1, $userid2, $datecreated){
        return Follow::addFollow($userid1, $userid2, $datecreated);
    }
    
    public static function checkFollow($userid1, $userid2){
        return Follow::checkFollow($userid1, $userid2);
    }
    
    public static function deleteFollow($userid1, $userid2){
        return Follow::deleteFollow($userid1, $userid2);
    }
    
    public static function addLike($statusid, $userid, $datecreated){
        return Like::addLike($statusid, $userid, $datecreated);
    }
    
    public static function deleteLike($statusid, $userid){
        return Like::deleteLike($statusid, $userid);
    }
    
    public static function getAmountLike($statusid){
        return Like::getAmountLike($statusid);
    }
    
    public function service($data) {
        $this->server->service($data);
    }
}
?>